<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../Styles/sure3.css" rel="stylesheet" type="text/css"/>
    <link href="../Styles/base1.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="markdown-body entry-content" itemprop="text">
    <h1><a href="#simd"  class="anchor" id="user-content-simd">

    </a>SIMD
    </h1>
    <h2><a href="#概述"  class="anchor" id="user-content-概述">

    </a>概述
    </h2>
    <p>SIMD（发音<code>/sim-dee/</code>）是“Single Instruction/Multiple Data”的缩写，意为“单指令，多数据”。它是 JavaScript 操作 CPU
        对应指令的接口，你可以看做这是一种不同的运算执行模式。与它相对的是 SISD（“Single Instruction/Single Data”），即“单指令，单数据”。</p>
    <p>SIMD 的含义是使用一个指令，完成多个数据的运算；SISD 的含义是使用一个指令，完成单个数据的运算，这是 JavaScript 的默认运算模式。显而易见，SIMD 的执行效率要高于 SISD，所以被广泛用于 3D
        图形运算、物理模拟等运算量超大的项目之中。</p>
    <p>为了理解 SIMD，请看下面的例子。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> [<span
            class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span
            class="pl-c1">4</span>];
<span class="pl-k">var</span> b <span class="pl-k">=</span> [<span class="pl-c1">5</span>, <span class="pl-c1">6</span>, <span
                class="pl-c1">7</span>, <span class="pl-c1">8</span>];
<span class="pl-k">var</span> c <span class="pl-k">=</span> [];

c[<span class="pl-c1">0</span>] <span class="pl-k">=</span> a[<span class="pl-c1">0</span>] <span class="pl-k">+</span> b[<span
                class="pl-c1">0</span>];
c[<span class="pl-c1">1</span>] <span class="pl-k">=</span> a[<span class="pl-c1">1</span>] <span class="pl-k">+</span> b[<span
                class="pl-c1">1</span>];
c[<span class="pl-c1">2</span>] <span class="pl-k">=</span> a[<span class="pl-c1">2</span>] <span class="pl-k">+</span> b[<span
                class="pl-c1">2</span>];
c[<span class="pl-c1">3</span>] <span class="pl-k">=</span> a[<span class="pl-c1">3</span>] <span class="pl-k">+</span> b[<span
                class="pl-c1">3</span>];
c <span class="pl-c"><span class="pl-c">//</span> Array[6, 8, 10, 12]</span></pre>
    </div>
    <p>上面代码中，数组<code>a</code>和<code>b</code>的对应成员相加，结果放入数组<code>c</code>。它的运算模式是依次处理每个数组成员，一共有四个数组成员，所以需要运算 4 次。</p>
    <p>如果采用 SIMD 模式，只要运算一次就够了。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">5</span>, <span class="pl-c1">6</span>, <span class="pl-c1">7</span>, <span class="pl-c1">8</span>);
<span class="pl-k">var</span> c <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-c1">add</span>(a, b); <span class="pl-c"><span class="pl-c">//</span> Float32x4[6, 8, 10, 12]</span></pre>
    </div>
    <p>上面代码之中，数组<code>a</code>和<code>b</code>的四个成员的各自相加，只用一条指令就完成了。因此，速度比上一种写法提高了 4 倍。</p>
    <p>一次 SIMD 运算，可以处理多个数据，这些数据被称为“通道”（lane）。上面代码中，一次运算了四个数据，因此就是四个通道。</p>
    <p>SIMD 通常用于矢量运算。</p>
    <div class="highlight highlight-source-js"><pre>v <span class="pl-k">+</span> w	<span class="pl-k">=</span> 〈v1, …, vn〉<span
            class="pl-k">+</span> 〈w1, …, wn〉
      <span class="pl-k">=</span> 〈v1<span class="pl-k">+</span>w1, …, vn<span class="pl-k">+</span>wn〉</pre>
    </div>
    <p>上面代码中，<code>v</code>和<code>w</code>是两个多元矢量。它们的加运算，在 SIMD 下是一个指令、而不是 n 个指令完成的，这就大大提高了效率。这对于 3D
        动画、图像处理、信号处理、数值处理、加密等运算是非常重要的。比如，Canvas 的<code>getImageData()</code>会将图像文件读成一个二进制数组，SIMD 就很适合对于这种数组的处理。</p>
    <p>总的来说，SIMD 是数据并行处理（parallelism）的一种手段，可以加速一些运算密集型操作的速度。将来与 WebAssembly 结合以后，可以让 JavaScript 达到二进制代码的运行速度。</p>
    <h2><a href="#数据类型"  class="anchor" id="user-content-数据类型">

    </a>数据类型
    </h2>
    <p>SIMD 提供 12 种数据类型，总长度都是 128 个二进制位。</p>
    <ul>
        <li>Float32x4：四个 32 位浮点数</li>
        <li>Float64x2：两个 64 位浮点数</li>
        <li>Int32x4：四个 32 位整数</li>
        <li>Int16x8：八个 16 位整数</li>
        <li>Int8x16：十六个 8 位整数</li>
        <li>Uint32x4：四个无符号的 32 位整数</li>
        <li>Uint16x8：八个无符号的 16 位整数</li>
        <li>Uint8x16：十六个无符号的 8 位整数</li>
        <li>Bool32x4：四个 32 位布尔值</li>
        <li>Bool16x8：八个 16 位布尔值</li>
        <li>Bool8x16：十六个 8 位布尔值</li>
        <li>Bool64x2：两个 64 位布尔值</li>
    </ul>
    <p>每种数据类型被<code>x</code>符号分隔成两部分，后面的部分表示通道数，前面的部分表示每个通道的宽度和类型。比如，<code>Float32x4</code>就表示这个值有 4 个通道，每个通道是一个 32
        位浮点数。</p>
    <p>每个通道之中，可以放置四种数据。</p>
    <ul>
        <li>浮点数（float，比如 1.0）</li>
        <li>带符号的整数（Int，比如-1）</li>
        <li>无符号的整数（Uint，比如 1）</li>
        <li>布尔值（Bool，包含<code>true</code>和<code>false</code>两种值）</li>
    </ul>
    <p>每种 SIMD 的数据类型都是一个函数方法，可以传入参数，生成对应的值。</p>
    <div class="highlight highlight-source-js">
        <pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Float32x4</span>(<span class="pl-c1">1.0</span>, <span class="pl-c1">2.0</span>, <span
                class="pl-c1">3.0</span>, <span class="pl-c1">4.0</span>);</pre>
    </div>
    <p>上面代码中，变量<code>a</code>就是一个 128 位、包含四个 32 位浮点数（即四个通道）的值。</p>
    <p>注意，这些数据类型方法都不是构造函数，前面不能加<code>new</code>，否则会报错。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> v <span class="pl-k">=</span> <span
            class="pl-k">new</span> <span class="pl-en">SIMD.Float32x4</span>(<span class="pl-c1">0</span>, <span
            class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>);
<span class="pl-c"><span class="pl-c">//</span> TypeError: SIMD.Float32x4 is not a constructor</span></pre>
    </div>
    <h2><a href="#静态方法数学运算"  class="anchor" id="user-content-静态方法数学运算">

    </a>静态方法：数学运算
    </h2>
    <p>每种数据类型都有一系列运算符，支持基本的数学运算。</p>
    <h3><a href="#simdtypeabssimdtypeneg"  class="anchor" id="user-content-simdtypeabssimdtypeneg">

    </a>SIMD.%type%.abs()，SIMD.%type%.neg()
    </h3>
    <p><code>abs</code>方法接受一个 SIMD 值作为参数，将它的每个通道都转成绝对值，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-k">-</span><span
            class="pl-c1">1</span>, <span class="pl-k">-</span><span class="pl-c1">2</span>, <span
            class="pl-c1">0</span>, <span class="pl-c1">NaN</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">abs</span>(a)
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1, 2, 0, NaN]</span></pre>
    </div>
    <p><code>neg</code>方法接受一个 SIMD 值作为参数，将它的每个通道都转成负值，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-k">-</span><span
            class="pl-c1">1</span>, <span class="pl-k">-</span><span class="pl-c1">2</span>, <span
            class="pl-c1">3</span>, <span class="pl-c1">0</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">neg</span>(a)
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1, 2, -3, -0]</span>

<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span
                class="pl-c1">NaN</span>, <span class="pl-c1">Infinity</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float64x2</span>.<span class="pl-en">neg</span>(b)
<span class="pl-c"><span class="pl-c">//</span> Float64x2[NaN, -Infinity]</span></pre>
    </div>
    <h3><a href="#simdtypeaddsimdtypeaddsaturate"  class="anchor"
           id="user-content-simdtypeaddsimdtypeaddsaturate">

    </a>SIMD.%type%.add()，SIMD.%type%.addSaturate()
    </h3>
    <p><code>add</code>方法接受两个 SIMD 值作为参数，将它们的每个通道相加，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1.0</span>, <span
            class="pl-c1">2.0</span>, <span class="pl-c1">3.0</span>, <span class="pl-c1">4.0</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">5.0</span>, <span class="pl-c1">10.0</span>, <span class="pl-c1">15.0</span>, <span
                class="pl-c1">20.0</span>);
<span class="pl-k">var</span> c <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-c1">add</span>(a, b);</pre>
    </div>
    <p>上面代码中，经过加法运算，新的 SIMD 值为<code>(6.0, 12.0, 18.0. 24.0)</code>。</p>
    <p><code>addSaturate</code>方法跟<code>add</code>方法的作用相同，都是两个通道相加，但是溢出的处理不一致。对于<code>add</code>方法，如果两个值相加发生溢出，溢出的二进制位会被丢弃;
        <code>addSaturate</code>方法则是返回该数据类型的最大值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Uint16x8</span>(<span class="pl-c1">65533</span>, <span
            class="pl-c1">65534</span>, <span class="pl-c1">65535</span>, <span class="pl-c1">65535</span>, <span
            class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span
            class="pl-c1">1</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Uint16x8</span>(<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">5000</span>, <span class="pl-c1">1</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Uint16x8</span>.<span class="pl-en">addSaturate</span>(a, b);
<span class="pl-c"><span class="pl-c">//</span> Uint16x8[65534, 65535, 65535, 65535, 2, 2, 2, 2]</span>

<span class="pl-k">var</span> c <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int16x8</span>(<span class="pl-c1">32765</span>, <span class="pl-c1">32766</span>, <span
                class="pl-c1">32767</span>, <span class="pl-c1">32767</span>, <span class="pl-c1">1</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>);
<span class="pl-k">var</span> d <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int16x8</span>(<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">5000</span>, <span class="pl-c1">1</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int16x8</span>.<span class="pl-en">addSaturate</span>(c, d);
<span class="pl-c"><span class="pl-c">//</span> Int16x8[32766, 32767, 32767, 32767, 2, 2, 2, 2]</span></pre>
    </div>
    <p>上面代码中，<code>Uint16</code>的最大值是 65535，<code>Int16</code>的最大值是 32767。一旦发生溢出，就返回这两个值。</p>
    <p>注意，<code>Uint32x4</code>和<code>Int32x4</code>这两种数据类型没有<code>addSaturate</code>方法。</p>
    <h3><a href="#simdtypesubsimdtypesubsaturate"  class="anchor"
           id="user-content-simdtypesubsimdtypesubsaturate">

    </a>SIMD.%type%.sub()，SIMD.%type%.subSaturate()
    </h3>
    <p><code>sub</code>方法接受两个 SIMD 值作为参数，将它们的每个通道相减，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-k">-</span><span
            class="pl-c1">1</span>, <span class="pl-k">-</span><span class="pl-c1">2</span>, <span
            class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-c1">sub</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Float32x4[-4, -5, 0, 1]</span></pre>
    </div>
    <p><code>subSaturate</code>方法跟<code>sub</code>方法的作用相同，都是两个通道相减，但是溢出的处理不一致。对于<code>sub</code>方法，如果两个值相减发生溢出，溢出的二进制位会被丢弃;
        <code>subSaturate</code>方法则是返回该数据类型的最小值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Uint16x8</span>(<span class="pl-c1">5</span>, <span
            class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span
            class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span
            class="pl-c1">1</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Uint16x8</span>(<span class="pl-c1">10</span>, <span class="pl-c1">1</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">1</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Uint16x8</span>.<span class="pl-en">subSaturate</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Uint16x8[0, 0, 0, 0, 0, 0, 0, 0]</span>

<span class="pl-k">var</span> c <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int16x8</span>(<span class="pl-k">-</span><span class="pl-c1">100</span>, <span
                class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span
                class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>);
<span class="pl-k">var</span> d <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int16x8</span>(<span class="pl-c1">32767</span>, <span class="pl-c1">0</span>, <span
                class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span
                class="pl-c1">0</span>, <span class="pl-c1">0</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int16x8</span>.<span class="pl-en">subSaturate</span>(c, d)
<span class="pl-c"><span class="pl-c">//</span> Int16x8[-32768, 0, 0, 0, 0, 0, 0, 0, 0]</span></pre>
    </div>
    <p>上面代码中，<code>Uint16</code>的最小值是<code>0</code>，<code>Int16</code>的最小值是<code>-32678</code>。一旦运算发生溢出，就返回最小值。</p>
    <h3><a href="#simdtypemulsimdtypedivsimdtypesqrt"  class="anchor"
           id="user-content-simdtypemulsimdtypedivsimdtypesqrt">

    </a>SIMD.%type%.mul()，SIMD.%type%.div()，SIMD.%type%.sqrt()
    </h3>
    <p><code>mul</code>方法接受两个 SIMD 值作为参数，将它们的每个通道相乘，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-k">-</span><span
            class="pl-c1">1</span>, <span class="pl-k">-</span><span class="pl-c1">2</span>, <span
            class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">mul</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Float32x4[-3, -6, 9, 12]</span></pre>
    </div>
    <p><code>div</code>方法接受两个 SIMD 值作为参数，将它们的每个通道相除，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">2</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">4</span>, <span class="pl-c1">4</span>, <span class="pl-c1">4</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">div</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Float32x4[0.5, 0.5, 0.5, 0.5]</span></pre>
    </div>
    <p><code>sqrt</code>方法接受一个 SIMD 值作为参数，求出每个通道的平方根，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> b <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span class="pl-c1">4</span>, <span
            class="pl-c1">8</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float64x2</span>.<span class="pl-en">sqrt</span>(b)
<span class="pl-c"><span class="pl-c">//</span> Float64x2[2, 2.8284271247461903]</span></pre>
    </div>
    <h3><a href="#simdfloattypereciprocalapproximationsimdtypereciprocalsqrtapproximation"
           class="anchor" id="user-content-simdfloattypereciprocalapproximationsimdtypereciprocalsqrtapproximation">

    </a>SIMD.%FloatType%.reciprocalApproximation()，SIMD.%type%.reciprocalSqrtApproximation()
    </h3>
    <p><code>reciprocalApproximation</code>方法接受一个 SIMD 值作为参数，求出每个通道的倒数（<code>1 / x</code>），作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">reciprocalApproximation</span>(a);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1, 0.5, 0.3333333432674408, 0.25]</span></pre>
    </div>
    <p><code>reciprocalSqrtApproximation</code>方法接受一个 SIMD 值作为参数，求出每个通道的平方根的倒数（<code>1 / (x^0.5)</code>），作为一个新的 SIMD
        值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">reciprocalSqrtApproximation</span>(a)
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1, 0.7071067690849304, 0.5773502588272095, 0.5]</span></pre>
    </div>
    <p>注意，只有浮点数的数据类型才有这两个方法。</p>
    <h3><a href="#simdintegertypeshiftleftbyscalar"  class="anchor"
           id="user-content-simdintegertypeshiftleftbyscalar">

    </a>SIMD.%IntegerType%.shiftLeftByScalar()
    </h3>
    <p><code>shiftLeftByScalar</code>方法接受一个 SIMD 值作为参数，然后将每个通道的值左移指定的位数，作为一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span
                class="pl-en">shiftLeftByScalar</span>(a, <span class="pl-c1">1</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[2, 4, 8, 16]</span></pre>
    </div>
    <p>如果左移后，新的值超出了当前数据类型的位数，溢出的部分会被丢弃。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> ix4 <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-k">var</span> jx4 <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span
                class="pl-en">shiftLeftByScalar</span>(ix4, <span class="pl-c1">32</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[0, 0, 0, 0]</span></pre>
    </div>
    <p>注意，只有整数的数据类型才有这个方法。</p>
    <h3><a href="#simdintegertypeshiftrightbyscalar"  class="anchor"
           id="user-content-simdintegertypeshiftrightbyscalar">

    </a>SIMD.%IntegerType%.shiftRightByScalar()
    </h3>
    <p><code>shiftRightByScalar</code>方法接受一个 SIMD 值作为参数，然后将每个通道的值右移指定的位数，返回一个新的 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-k">-</span><span
            class="pl-c1">8</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span
                class="pl-en">shiftRightByScalar</span>(a, <span class="pl-c1">1</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[0, 1, 2, -4]</span></pre>
    </div>
    <p>如果原来通道的值是带符号的值，则符号位保持不变，不受右移影响。如果是不带符号位的值，则右移后头部会补<code>0</code>。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Uint32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-k">-</span><span
            class="pl-c1">8</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Uint32x4</span>.<span
                class="pl-en">shiftRightByScalar</span>(a, <span class="pl-c1">1</span>);
<span class="pl-c"><span class="pl-c">//</span> Uint32x4[0, 1, 2, 2147483644]</span></pre>
    </div>
    <p>上面代码中，<code>-8</code>右移一位变成了<code>2147483644</code>，是因为对于 32 位无符号整数来说，<code>-8</code>的二进制形式是<code>11111111111111111111111111111000</code>，右移一位就变成了<code>01111111111111111111111111111100</code>，相当于<code>2147483644</code>。
    </p>
    <p>注意，只有整数的数据类型才有这个方法。</p>
    <h2><a href="#静态方法通道处理"  class="anchor" id="user-content-静态方法通道处理">

    </a>静态方法：通道处理
    </h2>
    <h3><a href="#simdtypecheck"  class="anchor" id="user-content-simdtypecheck">

    </a>SIMD.%type%.check()
    </h3>
    <p><code>check</code>方法用于检查一个值是否为当前类型的 SIMD 值。如果是的，就返回这个值，否则就报错。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">9</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">check</span>(a);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1, 2, 3, 9]</span>

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">check</span>([<span
                class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span
                class="pl-c1">4</span>]) <span class="pl-c"><span class="pl-c">//</span> 报错</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">check</span>(a) <span
                class="pl-c"><span class="pl-c">//</span> 报错</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">check</span>(<span class="pl-s"><span
                class="pl-pds">'</span>hello world<span class="pl-pds">'</span></span>) <span class="pl-c"><span
                class="pl-c">//</span> 报错</span></pre>
    </div>
    <h3><a href="#simdtypeextractlanesimdtypereplacelane"  class="anchor"
           id="user-content-simdtypeextractlanesimdtypereplacelane">

    </a>SIMD.%type%.extractLane()，SIMD.%type%.replaceLane()
    </h3>
    <p><code>extractLane</code>方法用于返回给定通道的值。它接受两个参数，分别是 SIMD 值和通道编号。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> t <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">extractLane</span>(t, <span
                class="pl-c1">2</span>) <span class="pl-c"><span class="pl-c">//</span> 3</span></pre>
    </div>
    <p><code>replaceLane</code>方法用于替换指定通道的值，并返回一个新的 SIMD 值。它接受三个参数，分别是原来的 SIMD 值、通道编号和新的通道值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> t <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">replaceLane</span>(t, <span
                class="pl-c1">2</span>, <span class="pl-c1">42</span>)
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1, 2, 42, 4]</span></pre>
    </div>
    <h3><a href="#simdtypeload"  class="anchor" id="user-content-simdtypeload">

    </a>SIMD.%type%.load()
    </h3>
    <p><code>load</code>方法用于从二进制数组读入数据，生成一个新的 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-k">new</span> <span class="pl-en">Int32Array</span>([<span class="pl-c1">1</span>,<span
            class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span
            class="pl-c1">5</span>,<span class="pl-c1">6</span>,<span class="pl-c1">7</span>,<span
            class="pl-c1">8</span>]);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-c1">load</span>(a, <span
                class="pl-c1">0</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[1, 2, 3, 4]</span>

<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-k">new</span> <span
                class="pl-en">Int32Array</span>([<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span
                class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">5</span>,<span
                class="pl-c1">6</span>,<span class="pl-c1">7</span>,<span class="pl-c1">8</span>]);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-c1">load</span>(a, <span
                class="pl-c1">2</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[3, 4, 5, 6]</span></pre>
    </div>
    <p><code>load</code>方法接受两个参数：一个二进制数组和开始读取的位置（从 0 开始）。如果位置不合法（比如<code>-1</code>或者超出二进制数组的大小），就会抛出一个错误。</p>
    <p>这个方法还有三个变种<code>load1()</code>、<code>load2()</code>、<code>load3()</code>，表示从指定位置开始，只加载一个通道、二个通道、三个通道的值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-c"><span class="pl-c">//</span> 格式</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-c1">load</span>(tarray, index)
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">load1</span>(tarray, index)
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">load2</span>(tarray, index)
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">load3</span>(tarray, index)

<span class="pl-c"><span class="pl-c">//</span> 实例</span>
<span class="pl-k">var</span> a <span class="pl-k">=</span> <span class="pl-k">new</span> <span
                class="pl-en">Int32Array</span>([<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span
                class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">5</span>,<span
                class="pl-c1">6</span>,<span class="pl-c1">7</span>,<span class="pl-c1">8</span>]);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">load1</span>(a, <span
                class="pl-c1">0</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[1, 0, 0, 0]</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">load2</span>(a, <span
                class="pl-c1">0</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[1, 2, 0, 0]</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">load3</span>(a, <span
                class="pl-c1">0</span>);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[1, 2, 3,0]</span></pre>
    </div>
    <h3><a href="#simdtypestore"  class="anchor" id="user-content-simdtypestore">

    </a>SIMD.%type%.store()
    </h3>
    <p><code>store</code>方法用于将一个 SIMD 值，写入一个二进制数组。它接受三个参数，分别是二进制数组、开始写入的数组位置、SIMD 值。它返回写入值以后的二进制数组。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> t1 <span class="pl-k">=</span> <span
            class="pl-k">new</span> <span class="pl-en">Int32Array</span>(<span class="pl-c1">8</span>);
<span class="pl-k">var</span> v1 <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span
                class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">store</span>(t1, <span
                class="pl-c1">0</span>, v1)
<span class="pl-c"><span class="pl-c">//</span> Int32Array[1, 2, 3, 4, 0, 0, 0, 0]</span>

<span class="pl-k">var</span> t2 <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-en">Int32Array</span>(<span
                class="pl-c1">8</span>);
<span class="pl-k">var</span> v2 <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span
                class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">store</span>(t2, <span
                class="pl-c1">2</span>, v2)
<span class="pl-c"><span class="pl-c">//</span> Int32Array[0, 0, 1, 2, 3, 4, 0, 0]</span></pre>
    </div>
    <p>上面代码中，<code>t1</code>是一个二进制数组，<code>v1</code>是一个 SIMD 值，只有四个通道。所以写入<code>t1</code>以后，只有前四个位置有值，后四个位置都是 0。而<code>t2</code>是从
        2 号位置开始写入，所以前两个位置和后两个位置都是 0。</p>
    <p>这个方法还有三个变种<code>store1()</code>、<code>store2()</code>和<code>store3()</code>，表示只写入一个通道、二个通道和三个通道的值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> tarray <span
            class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-en">Int32Array</span>(<span
            class="pl-c1">8</span>);
<span class="pl-k">var</span> value <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span
                class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">store1</span>(tarray, <span
                class="pl-c1">0</span>, value);
<span class="pl-c"><span class="pl-c">//</span> Int32Array[1, 0, 0, 0, 0, 0, 0, 0]</span></pre>
    </div>
    <h3><a href="#simdtypesplat"  class="anchor" id="user-content-simdtypesplat">

    </a>SIMD.%type%.splat()
    </h3>
    <p><code>splat</code>方法返回一个新的 SIMD 值，该值的所有通道都会设成同一个预先给定的值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-c1">SIMD</span>.<span
            class="pl-smi">Float32x4</span>.<span class="pl-en">splat</span>(<span class="pl-c1">3</span>);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[3, 3, 3, 3]</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float64x2</span>.<span class="pl-en">splat</span>(<span
                class="pl-c1">3</span>);
<span class="pl-c"><span class="pl-c">//</span> Float64x2[3, 3]</span></pre>
    </div>
    <p>如果省略参数，所有整数型的 SIMD 值都会设定<code>0</code>，浮点型的 SIMD 值都会设成<code>NaN</code>。</p>
    <h3><a href="#simdtypeswizzle"  class="anchor" id="user-content-simdtypeswizzle">

    </a>SIMD.%type%.swizzle()
    </h3>
    <p><code>swizzle</code>方法返回一个新的 SIMD 值，重新排列原有的 SIMD 值的通道顺序。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> t <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">swizzle</span>(t, <span
                class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">0</span>, <span class="pl-c1">3</span>);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[2,3,1,4]</span></pre>
    </div>
    <p>上面代码中，<code>swizzle</code>方法的第一个参数是原有的 SIMD 值，后面的参数对应将要返回的 SIMD 值的四个通道。它的意思是新的 SIMD 的四个通道，依次是原来 SIMD 值的 1 号通道、2
        号通道、0 号通道、3 号通道。由于 SIMD 值最多可以有 16 个通道，所以<code>swizzle</code>方法除了第一个参数以外，最多还可以接受 16 个参数。</p>
    <p>下面是另一个例子。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1.0</span>, <span
            class="pl-c1">2.0</span>, <span class="pl-c1">3.0</span>, <span class="pl-c1">4.0</span>);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1.0, 2.0, 3.0, 4.0]</span>

<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">swizzle</span>(a, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">1</span>);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1.0, 1.0, 2.0, 2.0]</span>

<span class="pl-k">var</span> c <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">swizzle</span>(a, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span
                class="pl-c1">3</span>, <span class="pl-c1">3</span>);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[4.0, 4.0, 4.0, 4.0]</span>

<span class="pl-k">var</span> d <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">swizzle</span>(a, <span class="pl-c1">3</span>, <span class="pl-c1">2</span>, <span
                class="pl-c1">1</span>, <span class="pl-c1">0</span>);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[4.0, 3.0, 2.0, 1.0]</span></pre>
    </div>
    <h3><a href="#simdtypeshuffle"  class="anchor" id="user-content-simdtypeshuffle">

    </a>SIMD.%type%.shuffle()
    </h3>
    <p><code>shuffle</code>方法从两个 SIMD 值之中取出指定通道，返回一个新的 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">5</span>, <span class="pl-c1">6</span>, <span class="pl-c1">7</span>, <span class="pl-c1">8</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">shuffle</span>(a, b, <span
                class="pl-c1">1</span>, <span class="pl-c1">5</span>, <span class="pl-c1">7</span>, <span class="pl-c1">2</span>);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[2, 6, 8, 3]</span></pre>
    </div>
    <p>上面代码中，<code>a</code>和<code>b</code>一共有 8 个通道，依次编号为 0 到 7。<code>shuffle</code>根据编号，取出相应的通道，返回一个新的 SIMD 值。</p>
    <h2><a href="#静态方法比较运算"  class="anchor" id="user-content-静态方法比较运算">

    </a>静态方法：比较运算
    </h2>
    <h3><a href="#simdtypeequalsimdtypenotequal"  class="anchor"
           id="user-content-simdtypeequalsimdtypenotequal">

    </a>SIMD.%type%.equal()，SIMD.%type%.notEqual()
    </h3>
    <p><code>equal</code>方法用来比较两个 SIMD 值<code>a</code>和<code>b</code>的每一个通道，根据两者是否精确相等（<code>a === b</code>），得到一个布尔值。最后，所有通道的比较结果，组成一个新的
        SIMD 值，作为掩码返回。<code>notEqual</code>方法则是比较两个通道是否不相等（<code>a !== b</code>）。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">9</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">1</span>, <span class="pl-c1">4</span>, <span class="pl-c1">7</span>, <span class="pl-c1">9</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">equal</span>(a,b)
<span class="pl-c"><span class="pl-c">//</span> Bool32x4[true, false, false, true]</span>

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">notEqual</span>(a,b);
<span class="pl-c"><span class="pl-c">//</span> Bool32x4[false, true, true, false]</span></pre>
    </div>
    <h3><a href="#simdtypegreaterthansimdtypegreaterthanorequal"  class="anchor"
           id="user-content-simdtypegreaterthansimdtypegreaterthanorequal">

    </a>SIMD.%type%.greaterThan()，SIMD.%type%.greaterThanOrEqual()
    </h3>
    <p><code>greatThan</code>方法用来比较两个 SIMD
        值<code>a</code>和<code>b</code>的每一个通道，如果在该通道中，<code>a</code>较大就得到<code>true</code>，否则得到<code>false</code>。最后，所有通道的比较结果，组成一个新的
        SIMD 值，作为掩码返回。<code>greaterThanOrEqual</code>则是比较<code>a</code>是否大于等于<code>b</code>。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">6</span>, <span class="pl-c1">3</span>, <span class="pl-c1">11</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">1</span>, <span class="pl-c1">4</span>, <span class="pl-c1">7</span>, <span class="pl-c1">9</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">greaterThan</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Bool32x4[false, true, false, true]</span>

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">greaterThanOrEqual</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Bool32x4[true, true, false, true]</span></pre>
    </div>
    <h3><a href="#simdtypelessthansimdtypelessthanorequal"  class="anchor"
           id="user-content-simdtypelessthansimdtypelessthanorequal">

    </a>SIMD.%type%.lessThan()，SIMD.%type%.lessThanOrEqual()
    </h3>
    <p><code>lessThan</code>方法用来比较两个 SIMD
        值<code>a</code>和<code>b</code>的每一个通道，如果在该通道中，<code>a</code>较小就得到<code>true</code>，否则得到<code>false</code>。最后，所有通道的比较结果，会组成一个新的
        SIMD 值，作为掩码返回。<code>lessThanOrEqual</code>方法则是比较<code>a</code>是否等于<code>b</code>。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">11</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">1</span>, <span class="pl-c1">4</span>, <span class="pl-c1">7</span>, <span class="pl-c1">9</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">lessThan</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Bool32x4[false, true, true, false]</span>

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">lessThanOrEqual</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Bool32x4[true, true, true, false]</span></pre>
    </div>
    <h3><a href="#simdtypeselect"  class="anchor" id="user-content-simdtypeselect">

    </a>SIMD.%type%.select()
    </h3>
    <p><code>select</code>方法通过掩码生成一个新的 SIMD 值。它接受三个参数，分别是掩码和两个 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">5</span>, <span class="pl-c1">6</span>, <span class="pl-c1">7</span>, <span class="pl-c1">8</span>);

<span class="pl-k">var</span> mask <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Bool32x4</span>(<span
                class="pl-c1">true</span>, <span class="pl-c1">false</span>, <span class="pl-c1">false</span>, <span
                class="pl-c1">true</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-c1">select</span>(mask, a, b);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1, 6, 7, 4]</span></pre>
    </div>
    <p>上面代码中，<code>select</code>方法接受掩码和两个 SIMD 值作为参数。当某个通道对应的掩码为<code>true</code>时，会选择第一个 SIMD 值的对应通道，否则选择第二个 SIMD
        值的对应通道。</p>
    <p>这个方法通常与比较运算符结合使用。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">0</span>, <span
            class="pl-c1">12</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">0</span>, <span class="pl-c1">6</span>, <span class="pl-c1">7</span>, <span class="pl-c1">50</span>);

<span class="pl-k">var</span> mask <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">lessThan</span>(a,b);
<span class="pl-c"><span class="pl-c">//</span> Bool32x4[false, false, true, true]</span>

<span class="pl-k">var</span> result <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-c1">select</span>(mask, a, b);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[0, 6, 3, 4]</span></pre>
    </div>
    <p>上面代码中，先通过<code>lessThan</code>方法生成一个掩码，然后通过<code>select</code>方法生成一个由每个通道的较小值组成的新的 SIMD 值。</p>
    <h3><a href="#simdbooleantypealltruesimdbooleantypeanytrue"  class="anchor"
           id="user-content-simdbooleantypealltruesimdbooleantypeanytrue">

    </a>SIMD.%BooleanType%.allTrue()，SIMD.%BooleanType%.anyTrue()
    </h3>
    <p><code>allTrue</code>方法接受一个 SIMD 值作为参数，然后返回一个布尔值，表示该 SIMD 值的所有通道是否都为<code>true</code>。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Bool32x4</span>(<span class="pl-c1">true</span>, <span
            class="pl-c1">true</span>, <span class="pl-c1">true</span>, <span class="pl-c1">true</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Bool32x4</span>(<span class="pl-c1">true</span>, <span class="pl-c1">false</span>, <span
                class="pl-c1">true</span>, <span class="pl-c1">true</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Bool32x4</span>.<span class="pl-en">allTrue</span>(a); <span
                class="pl-c"><span class="pl-c">//</span> true</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Bool32x4</span>.<span class="pl-en">allTrue</span>(b); <span
                class="pl-c"><span class="pl-c">//</span> false</span></pre>
    </div>
    <p><code>anyTrue</code>方法则是只要有一个通道为<code>true</code>，就返回<code>true</code>，否则返回<code>false</code>。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Bool32x4</span>(<span class="pl-c1">false</span>, <span
            class="pl-c1">false</span>, <span class="pl-c1">false</span>, <span class="pl-c1">false</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Bool32x4</span>(<span class="pl-c1">false</span>, <span class="pl-c1">false</span>, <span
                class="pl-c1">true</span>, <span class="pl-c1">false</span>);

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Bool32x4</span>.<span class="pl-en">anyTrue</span>(a); <span
                class="pl-c"><span class="pl-c">//</span> false</span>
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Bool32x4</span>.<span class="pl-en">anyTrue</span>(b); <span
                class="pl-c"><span class="pl-c">//</span> true</span></pre>
    </div>
    <p>注意，只有四种布尔值数据类型（<code>Bool32x4</code>、<code>Bool16x8</code>、<code>Bool8x16</code>、<code>Bool64x2</code>）才有这两个方法。
    </p>
    <p>这两个方法通常与比较运算符结合使用。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> ax4    <span
            class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
            class="pl-c1">1.0</span>, <span class="pl-c1">2.0</span>, <span class="pl-c1">3.0</span>, <span
            class="pl-c1">4.0</span>);
<span class="pl-k">var</span> bx4    <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">0.0</span>, <span class="pl-c1">6.0</span>, <span class="pl-c1">7.0</span>, <span
                class="pl-c1">8.0</span>);
<span class="pl-k">var</span> ix4    <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">lessThan</span>(ax4, bx4);
<span class="pl-k">var</span> b1     <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span
                class="pl-en">allTrue</span>(ix4); <span class="pl-c"><span class="pl-c">//</span> false</span>
<span class="pl-k">var</span> b2     <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span
                class="pl-en">anyTrue</span>(ix4); <span class="pl-c"><span class="pl-c">//</span> true</span></pre>
    </div>
    <h3><a href="#simdtypeminsimdtypeminnum"  class="anchor"
           id="user-content-simdtypeminsimdtypeminnum">

    </a>SIMD.%type%.min()，SIMD.%type%.minNum()
    </h3>
    <p><code>min</code>方法接受两个 SIMD 值作为参数，将两者的对应通道的较小值，组成一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-k">-</span><span
            class="pl-c1">1</span>, <span class="pl-k">-</span><span class="pl-c1">2</span>, <span
            class="pl-c1">3</span>, <span class="pl-c1">5.2</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">0</span>, <span class="pl-k">-</span><span class="pl-c1">4</span>, <span
                class="pl-c1">6</span>, <span class="pl-c1">5.5</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">min</span>(a, b);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[-1, -4, 3, 5.2]</span></pre>
    </div>
    <p>如果有一个通道的值是<code>NaN</code>，则会优先返回<code>NaN</code>。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> c <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span class="pl-c1">NaN</span>, <span
            class="pl-c1">Infinity</span>)
<span class="pl-k">var</span> d <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span
                class="pl-c1">1337</span>, <span class="pl-c1">42</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float64x2</span>.<span class="pl-en">min</span>(c, d);
<span class="pl-c"><span class="pl-c">//</span> Float64x2[NaN, 42]</span></pre>
    </div>
    <p><code>minNum</code>方法与<code>min</code>的作用一模一样，唯一的区别是如果有一个通道的值是<code>NaN</code>，则会优先返回另一个通道的值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> ax4 <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1.0</span>, <span
            class="pl-c1">2.0</span>, <span class="pl-c1">NaN</span>, <span class="pl-c1">NaN</span>);
<span class="pl-k">var</span> bx4 <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">2.0</span>, <span class="pl-c1">1.0</span>, <span class="pl-c1">3.0</span>, <span
                class="pl-c1">NaN</span>);
<span class="pl-k">var</span> cx4 <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">min</span>(ax4, bx4);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1.0, 1.0, NaN, NaN]</span>
<span class="pl-k">var</span> dx4 <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">minNum</span>(ax4, bx4);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[1.0, 1.0, 3.0, NaN]</span></pre>
    </div>
    <h3><a href="#simdtypemaxsimdtypemaxnum"  class="anchor"
           id="user-content-simdtypemaxsimdtypemaxnum">

    </a>SIMD.%type%.max()，SIMD.%type%.maxNum()
    </h3>
    <p><code>max</code>方法接受两个 SIMD 值作为参数，将两者的对应通道的较大值，组成一个新的 SIMD 值返回。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-k">-</span><span
            class="pl-c1">1</span>, <span class="pl-k">-</span><span class="pl-c1">2</span>, <span
            class="pl-c1">3</span>, <span class="pl-c1">5.2</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span
                class="pl-c1">0</span>, <span class="pl-k">-</span><span class="pl-c1">4</span>, <span
                class="pl-c1">6</span>, <span class="pl-c1">5.5</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-en">max</span>(a, b);
<span class="pl-c"><span class="pl-c">//</span> Float32x4[0, -2, 6, 5.5]</span></pre>
    </div>
    <p>如果有一个通道的值是<code>NaN</code>，则会优先返回<code>NaN</code>。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> c <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span class="pl-c1">NaN</span>, <span
            class="pl-c1">Infinity</span>)
<span class="pl-k">var</span> d <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span
                class="pl-c1">1337</span>, <span class="pl-c1">42</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float64x2</span>.<span class="pl-en">max</span>(c, d)
<span class="pl-c"><span class="pl-c">//</span> Float64x2[NaN, Infinity]</span></pre>
    </div>
    <p><code>maxNum</code>方法与<code>max</code>的作用一模一样，唯一的区别是如果有一个通道的值是<code>NaN</code>，则会优先返回另一个通道的值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> c <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span class="pl-c1">NaN</span>, <span
            class="pl-c1">Infinity</span>)
<span class="pl-k">var</span> d <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-en">Float64x2</span>(<span
                class="pl-c1">1337</span>, <span class="pl-c1">42</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Float64x2</span>.<span class="pl-en">maxNum</span>(c, d)
<span class="pl-c"><span class="pl-c">//</span> Float64x2[1337, Infinity]</span></pre>
    </div>
    <h2><a href="#静态方法位运算"  class="anchor" id="user-content-静态方法位运算">

    </a>静态方法：位运算
    </h2>
    <h3><a href="#simdtypeandsimdtypeorsimdtypexorsimdtypenot"  class="anchor"
           id="user-content-simdtypeandsimdtypeorsimdtypexorsimdtypenot">

    </a>SIMD.%type%.and()，SIMD.%type%.or()，SIMD.%type%.xor()，SIMD.%type%.not()
    </h3>
    <p><code>and</code>方法接受两个 SIMD 值作为参数，返回两者对应的通道进行二进制<code>AND</code>运算（<code>&amp;</code>）后得到的新的 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int32x4</span>(<span class="pl-c1">5</span>, <span class="pl-c1">5</span>, <span
                class="pl-c1">5</span>, <span class="pl-c1">5</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">and</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Int32x4[1, 0, 4, 0]</span></pre>
    </div>
    <p>
        上面代码中，以通道<code>0</code>为例，<code>1</code>的二进制形式是<code>0001</code>，<code>5</code>的二进制形式是<code>01001</code>，所以进行<code>AND</code>运算以后，得到<code>0001</code>。
    </p>
    <p><code>or</code>方法接受两个 SIMD 值作为参数，返回两者对应的通道进行二进制<code>OR</code>运算（<code>|</code>）后得到的新的 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int32x4</span>(<span class="pl-c1">5</span>, <span class="pl-c1">5</span>, <span
                class="pl-c1">5</span>, <span class="pl-c1">5</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">or</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Int32x4[5, 7, 5, 13]</span></pre>
    </div>
    <p><code>xor</code>方法接受两个 SIMD 值作为参数，返回两者对应的通道进行二进制”异或“运算（<code>^</code>）后得到的新的 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>);
<span class="pl-k">var</span> b <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span
                class="pl-en">Int32x4</span>(<span class="pl-c1">5</span>, <span class="pl-c1">5</span>, <span
                class="pl-c1">5</span>, <span class="pl-c1">5</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">xor</span>(a, b)
<span class="pl-c"><span class="pl-c">//</span> Int32x4[4, 7, 1, 13]</span></pre>
    </div>
    <p><code>not</code>方法接受一个 SIMD 值作为参数，返回每个通道进行二进制”否“运算（<code>~</code>）后得到的新的 SIMD 值。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Int32x4</span>(<span class="pl-c1">1</span>, <span
            class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">not</span>(a)
<span class="pl-c"><span class="pl-c">//</span> Int32x4[-2, -3, -5, -9]</span></pre>
    </div>
    <p>上面代码中，<code>1</code>的否运算之所以得到<code>-2</code>，是因为在计算机内部，负数采用”2
        的补码“这种形式进行表示。也就是说，整数<code>n</code>的负数形式<code>-n</code>，是对每一个二进制位取反以后，再加上 1。因此，直接取反就相当于负数形式再减去 1，比如<code>1</code>的负数形式是<code>-1</code>，再减去
        1，就得到了<code>-2</code>。</p>
    <h2><a href="#静态方法数据类型转换"  class="anchor" id="user-content-静态方法数据类型转换">

    </a>静态方法：数据类型转换
    </h2>
    <p>SIMD 提供以下方法，用来将一种数据类型转为另一种数据类型。</p>
    <ul>
        <li><code>SIMD.%type%.fromFloat32x4()</code></li>
        <li><code>SIMD.%type%.fromFloat32x4Bits()</code></li>
        <li><code>SIMD.%type%.fromFloat64x2Bits()</code></li>
        <li><code>SIMD.%type%.fromInt32x4()</code></li>
        <li><code>SIMD.%type%.fromInt32x4Bits()</code></li>
        <li><code>SIMD.%type%.fromInt16x8Bits()</code></li>
        <li><code>SIMD.%type%.fromInt8x16Bits()</code></li>
        <li><code>SIMD.%type%.fromUint32x4()</code></li>
        <li><code>SIMD.%type%.fromUint32x4Bits()</code></li>
        <li><code>SIMD.%type%.fromUint16x8Bits()</code></li>
        <li><code>SIMD.%type%.fromUint8x16Bits()</code></li>
    </ul>
    <p>带有<code>Bits</code>后缀的方法，会原封不动地将二进制位拷贝到新的数据类型；不带后缀的方法，则会进行数据类型转换。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> t <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1.0</span>, <span
            class="pl-c1">2.0</span>, <span class="pl-c1">3.0</span>, <span class="pl-c1">4.0</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">fromFloat32x4</span>(t);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[1, 2, 3, 4]</span>

<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int32x4</span>.<span class="pl-en">fromFloat32x4Bits</span>(t);
<span class="pl-c"><span class="pl-c">//</span> Int32x4[1065353216, 1073741824, 1077936128, 1082130432]</span></pre>
    </div>
    <p>上面代码中，<code>fromFloat32x4</code>是将浮点数转为整数，然后存入新的数据类型；<code>fromFloat32x4Bits</code>则是将二进制位原封不动地拷贝进入新的数据类型，然后进行解读。
    </p>
    <p><code>Bits</code>后缀的方法，还可以用于通道数目不对等的拷贝。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> t <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">1.0</span>, <span
            class="pl-c1">2.0</span>, <span class="pl-c1">3.0</span>, <span class="pl-c1">4.0</span>);
<span class="pl-c1">SIMD</span>.<span class="pl-smi">Int16x8</span>.<span class="pl-en">fromFloat32x4Bits</span>(t);
<span class="pl-c"><span class="pl-c">//</span> Int16x8[0, 16256, 0, 16384, 0, 16448, 0, 16512]</span></pre>
    </div>
    <p>上面代码中，原始 SIMD 值<code>t</code>是 4 通道的，而目标值是 8 通道的。</p>
    <p>如果数据转换时，原通道的数据大小，超过了目标通道的最大宽度，就会报错。</p>
    <h2><a href="#实例方法"  class="anchor" id="user-content-实例方法">

    </a>实例方法
    </h2>
    <h3><a href="#simdtypeprototypetostring"  class="anchor"
           id="user-content-simdtypeprototypetostring">

    </a>SIMD.%type%.prototype.toString()
    </h3>
    <p><code>toString</code>方法返回一个 SIMD 值的字符串形式。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">var</span> a <span class="pl-k">=</span> <span
            class="pl-c1">SIMD</span>.<span class="pl-en">Float32x4</span>(<span class="pl-c1">11</span>, <span
            class="pl-c1">22</span>, <span class="pl-c1">33</span>, <span class="pl-c1">44</span>);
<span class="pl-smi">a</span>.<span class="pl-c1">toString</span>() <span class="pl-c"><span class="pl-c">//</span> "SIMD.Float32x4(11, 22, 33, 44)"</span></pre>
    </div>
    <h2><a href="#实例求平均值"  class="anchor" id="user-content-实例求平均值">

    </a>实例：求平均值
    </h2>
    <p>正常模式下，计算<code>n</code>个值的平均值，需要运算<code>n</code>次。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">function</span> <span
            class="pl-en">average</span>(<span class="pl-smi">list</span>) {
  <span class="pl-k">var</span> n <span class="pl-k">=</span> <span class="pl-smi">list</span>.<span class="pl-c1">length</span>;
  <span class="pl-k">var</span> sum <span class="pl-k">=</span> <span class="pl-c1">0.0</span>;
  <span class="pl-k">for</span> (<span class="pl-k">var</span> i <span class="pl-k">=</span> <span
                class="pl-c1">0</span>; i <span class="pl-k">&lt;</span> n; i<span class="pl-k">++</span>) {
    sum <span class="pl-k">+=</span> list[i];
  }
  <span class="pl-k">return</span> sum <span class="pl-k">/</span> n;
}</pre>
    </div>
    <p>使用 SIMD，可以将计算次数减少到<code>n</code>次的四分之一。</p>
    <div class="highlight highlight-source-js"><pre><span class="pl-k">function</span> <span
            class="pl-en">average</span>(<span class="pl-smi">list</span>) {
  <span class="pl-k">var</span> n <span class="pl-k">=</span> <span class="pl-smi">list</span>.<span class="pl-c1">length</span>;
  <span class="pl-k">var</span> sum <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">splat</span>(<span class="pl-c1">0.0</span>);
  <span class="pl-k">for</span> (<span class="pl-k">var</span> i <span class="pl-k">=</span> <span
                class="pl-c1">0</span>; i <span class="pl-k">&lt;</span> n; i <span class="pl-k">+=</span> <span
                class="pl-c1">4</span>) {
    sum <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-c1">add</span>(
      sum,
      <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span class="pl-c1">load</span>(list, i)
    );
  }
  <span class="pl-k">var</span> total <span class="pl-k">=</span> <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">extractLane</span>(sum, <span class="pl-c1">0</span>) <span class="pl-k">+</span>
              <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">extractLane</span>(sum, <span class="pl-c1">1</span>) <span class="pl-k">+</span>
              <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">extractLane</span>(sum, <span class="pl-c1">2</span>) <span class="pl-k">+</span>
              <span class="pl-c1">SIMD</span>.<span class="pl-smi">Float32x4</span>.<span
                class="pl-en">extractLane</span>(sum, <span class="pl-c1">3</span>);
  <span class="pl-k">return</span> total <span class="pl-k">/</span> n;
}</pre>
    </div>
    <p>上面代码先是每隔四位，将所有的值读入一个 SIMD，然后立刻累加。然后，得到累加值四个通道的总和，再除以<code>n</code>就可以了。</p>
</div>
</body>
</html>
